package com.lb.trac.controller.common.loaders;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lb.trac.pojo.Stati;
import com.lb.trac.service.SearchService;
import com.lb.trac.util.StatoConstant;

public class LoadStati implements HttpObjectsLoader {

	private SearchService searchService;
	
	public void load(HttpServletRequest request, HttpServletResponse response) {
		Stati[] stati = (Stati[]) request.getSession(false).getAttribute("stati");
		if (request.getSession(false).getAttribute("stati") == null) {
			stati = getSearchService().findAllStati();
			List<Stati> _stati  = new ArrayList<Stati>();
			for (int i = 0; i < stati.length; i++) {
				Stati s = stati[i];
				if(!s.equals(StatoConstant.ANNULLATO)){
					_stati.add(s);
				}
			}
			request.getSession(false).setAttribute("stati", stati);
		}
	}

	public SearchService getSearchService() {
		return searchService;
	}

	public void setSearchService(SearchService searchService) {
		this.searchService = searchService;
	}

}
